/*
 * Copyright (c) 2020 Fraunhofer FOKUS and others. All rights reserved.
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contact: mosaic@fokus.fraunhofer.de
 */
package org.eclipse.mosaic.interactions.vehicle;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.eclipse.mosaic.rti.api.Interaction;

import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

/**
 * This extension of {@link Interaction} is sent by carla ambassador, spawn the carla vehicle in sumo.
 */
public class CarlaVehicleRegistration extends Interaction {

    private static final long serialVersionUID = 1L;

    /**
     * String identifying the type of this interaction.
     */
    public final static String TYPE_ID = createTypeIdentifier(CarlaVehicleRegistration.class);

    private final String vehicleId;

    private final String type;

    private final String color;

    private final String routeId;

    private final int numberOfWheels;

    private final double length;

    private final double width;

    private final double height;

    private final String vehicleClass;

    private final String shapeClass;

    public CarlaVehicleRegistration(long time,
                                    String vehicleId,
                                    String type,
                                    String color,
                                    String routeId,
                                    int numberOfWheels,
                                    double length,
                                    double width,
                                    double height,
                                    String vehicleClass,
                                    String shapeClass) {
        super(time);
        this.vehicleId = vehicleId;
        this.type = type;
        this.color = color;
        this.routeId = routeId;
        this.numberOfWheels = numberOfWheels;
        this.length = length;
        this.width = width;
        this.height = height;
        this.vehicleClass = vehicleClass;
        this.shapeClass = shapeClass;
    }

    public String getVehicleId() {
        return vehicleId;
    }

    public String getType() {
        return type;
    }

    public String getColor() {
        return color;
    }

    public String getRouteId() {
        return routeId;
    }

    public int getNumberOfWheels() {
        return numberOfWheels;
    }

    public double getLength() {
        return length;
    }

    public double getWidth() {
        return width;
    }

    public double getHeight() {
        return height;
    }

    public String getVehicleClass() {
        return vehicleClass;
    }

    public String getShapeClass() {
        return shapeClass;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(5, 71)
                .append(vehicleId)
                .append(type)
                .append(color)
                .append(routeId)
                .append(numberOfWheels)
                .append(length)
                .append(width)
                .append(height)
                .append(vehicleClass)
                .append(shapeClass)
                .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != getClass()) {
            return false;
        }

        CarlaVehicleRegistration other = (CarlaVehicleRegistration) obj;
        return new EqualsBuilder()
                .append(this.vehicleId, other.vehicleId)
                .append(this.type, other.type)
                .append(this.color, other.color)
                .append(this.routeId, other.routeId)
                .append(this.numberOfWheels, other.numberOfWheels)
                .append(this.length, other.length)
                .append(this.width, other.width)
                .append(this.height, other.height)
                .append(this.vehicleClass, other.vehicleClass)
                .append(this.shapeClass, other.shapeClass)
                .isEquals();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, SHORT_PREFIX_STYLE)
                .appendSuper(super.toString())
                .append("vehicleId", vehicleId)
                .append("type", type)
                .append("color", color)
                .append("routeId", routeId)
                .append("numberOfWheels", numberOfWheels)
                .append("length", length)
                .append("width", width)
                .append("height", height)
                .append("vehicleClass", vehicleClass)
                .append("shapeClass", shapeClass)
                .toString();
    }
}
